package com.lingyun.ucm.common.rmi;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 
 * @author Terrence2013
 * 2018年1月24日 上午9:49:11
 * TODO
 */
public class RMIUtil {
    private RMIUtil() {
    }

    /**
     * 获取rmi访问url
     * @param host
     * @param port
     * @param instanceName
     * @return
     */
    public static String getRMIURL(String host, int port, String instanceName) {
        StringBuilder url = new StringBuilder();
        url.append("rmi://")
           .append(host).append(":")
           .append(port).append("/")
           .append(instanceName);
        return url.toString();
    }

    /**
     * 获取本地IP地址
     * @return
     */
    public static String getLocalIP() {
        try {
            return InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        return "";
    }
}
